package com.bjpowernode.stusys.service.impl;

import com.bjpowernode.stusys.entity.Student;
import com.bjpowernode.stusys.exception.SysException;
import com.bjpowernode.stusys.mapper.StudentDao;
import com.bjpowernode.stusys.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jy
 * @version 1.0
 * @date 2021/12/1 22:28
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    public PageInfo<Student> findPage(Student student, int pageNum, int pageSize) {
        return PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->{
           studentDao.find(student);
        });
    }

    @Override
    public void deleteById(int id) {
        studentDao.deleteById(id);
    }

    @Override
    public void addStu(Student student) {
        studentDao.save(student);
    }

    @Override
    public Student findById(int id) {
        return studentDao.selectById(id);
    }


    @Override
    public void edit(Student student) {
        studentDao.updateById(student);
    }




/*    @Override
    public List<Student> findAllStudents() {
        List<Student> list = studentDao.findAllStudents();
        if (list == null){
            throw new SysException("没有任何学生!");
        }
        return list;
    }*/


}